"use strict";

/*
 * MikoPBX - free phone system for small business
 * Copyright © 2017-2023 Alexey Portnov and Nikolay Beketov
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with this program.
 * If not, see <https://www.gnu.org/licenses/>.
 */

/* global Sentry, globalPBXVersion, globalPBXLicense,
globalLastSentryEventId, globalTranslate, localStorage */

/**
 * Shows the Sentry report dialog for error reporting.
 * @param {string} hash - Hash value for identifying the error.
 * @param {string} sentryEventId - Sentry event ID for the error.
 */
function globalShowSentryReportDialog(hash, sentryEventId) {
  var itIsKnownError = localStorage.getItem("sentry_lastError".concat(hash));

  if (itIsKnownError === null) {
    if (typeof {
      globalTranslate: globalTranslate
    } !== "undefined" && Object.keys(globalTranslate).length > 0) {
      Sentry.showReportDialog({
        eventId: sentryEventId,
        title: globalTranslate.sntry_Title,
        subtitle: globalTranslate.sntry_Subtitle,
        subtitle2: globalTranslate.sntry_Subtitle2,
        labelComments: globalTranslate.sntry_LabelComments,
        labelClose: globalTranslate.sntry_LabelClose,
        labelSubmit: globalTranslate.sntry_LabelSubmit,
        errorGeneric: globalTranslate.sntry_ErrorGeneric,
        errorFormEntry: globalTranslate.sntry_ErrorFormEntry,
        successMessage: globalTranslate.sntry_SuccessMessage
      });
    } else {
      Sentry.showReportDialog({
        eventId: sentryEventId
      });
    }

    localStorage.setItem("sentry_lastError".concat(hash), 'theFormHasAlreadySent');
  }
}

Sentry.onLoad(function () {
  Sentry.init({
    dsn: 'https://07be0eff8a5c463fbac3e90ae5c7d039@sentry.miko.ru/1',
    release: "mikopbx@".concat(globalPBXVersion),
    beforeSend: function beforeSend(event, hint) {
      // Check if it is an exception, and if so, show the report dialog
      if (event.exception) {
        var error = hint.originalException;

        if (error && error.message && error.message.length > 0) {
          // Log the error message to the console
          console.error("Captured error:", error); // Generate a hash from the error message

          var s = error.message;
          var hash = 0;
          var i;
          var chr;

          for (i = 0; i < s.length; i++) {
            chr = s.charCodeAt(i);
            hash = (hash << 5) - hash + chr;
            hash |= 0; // Convert to 32bit integer
          } // Show the Sentry report dialog


          globalShowSentryReportDialog(hash, hint.eventId);
        }
      } // Return the event for Sentry to process


      return event;
    }
  });
  Sentry.configureScope(function (scope) {
    scope.setUser({
      id: globalPBXLicense
    });
    scope.setTag('library', 'web-interface');
  });

  if (globalLastSentryEventId) {
    globalShowSentryReportDialog(globalLastSentryEventId);
  }
});
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9tYWluL3NlbnRyeS1lcnJvci1sb2dnZXIuanMiXSwibmFtZXMiOlsiZ2xvYmFsU2hvd1NlbnRyeVJlcG9ydERpYWxvZyIsImhhc2giLCJzZW50cnlFdmVudElkIiwiaXRJc0tub3duRXJyb3IiLCJsb2NhbFN0b3JhZ2UiLCJnZXRJdGVtIiwiZ2xvYmFsVHJhbnNsYXRlIiwiT2JqZWN0Iiwia2V5cyIsImxlbmd0aCIsIlNlbnRyeSIsInNob3dSZXBvcnREaWFsb2ciLCJldmVudElkIiwidGl0bGUiLCJzbnRyeV9UaXRsZSIsInN1YnRpdGxlIiwic250cnlfU3VidGl0bGUiLCJzdWJ0aXRsZTIiLCJzbnRyeV9TdWJ0aXRsZTIiLCJsYWJlbENvbW1lbnRzIiwic250cnlfTGFiZWxDb21tZW50cyIsImxhYmVsQ2xvc2UiLCJzbnRyeV9MYWJlbENsb3NlIiwibGFiZWxTdWJtaXQiLCJzbnRyeV9MYWJlbFN1Ym1pdCIsImVycm9yR2VuZXJpYyIsInNudHJ5X0Vycm9yR2VuZXJpYyIsImVycm9yRm9ybUVudHJ5Iiwic250cnlfRXJyb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kub25Mb2FkKCgpID0+IHtcbiAgICBTZW50cnkuaW5pdCh7XG4gICAgICAgIGRzbjogJ2h0dHBzOi8vMDdiZTBlZmY4YTVjNDYzZmJhYzNlOTBhZTVjN2QwMzlAc2VudHJ5Lm1pa28ucnUvMScsXG4gICAgICAgIHJlbGVhc2U6IGBtaWtvcGJ4QCR7Z2xvYmFsUEJYVmVyc2lvbn1gLFxuICAgICAgICBiZWZvcmVTZW5kKGV2ZW50LCBoaW50KSB7XG4gICAgICAgICAgICAvLyBDaGVjayBpZiBpdCBpcyBhbiBleGNlcHRpb24sIGFuZCBpZiBzbywgc2hvdyB0aGUgcmVwb3J0IGRpYWxvZ1xuICAgICAgICAgICAgaWYgKGV2ZW50LmV4Y2VwdGlvbikge1xuICAgICAgICAgICAgICAgIGNvbnN0IGVycm9yID0gaGludC5vcmlnaW5hbEV4Y2VwdGlvbjtcbiAgICAgICAgICAgICAgICBpZiAoZXJyb3IgJiYgZXJyb3IubWVzc2FnZSAmJiBlcnJvci5tZXNzYWdlLmxlbmd0aCA+IDApIHtcblxuICAgICAgICAgICAgICAgICAgICAvLyBMb2cgdGhlIGVycm9yIG1lc3NhZ2UgdG8gdGhlIGNvbnNvbGVcbiAgICAgICAgICAgICAgICAgICAgY29uc29sZS5lcnJvcihcIkNhcHR1cmVkIGVycm9yOlwiLCBlcnJvcik7XG5cbiAgICAgICAgICAgICAgICAgICAgLy8gR2VuZXJhdGUgYSBoYXNoIGZyb20gdGhlIGVycm9yIG1lc3NhZ2VcbiAgICAgICAgICAgICAgICAgICAgY29uc3QgcyA9IGVycm9yLm1lc3NhZ2U7XG4gICAgICAgICAgICAgICAgICAgIGxldCBoYXNoID0gMDtcbiAgICAgICAgICAgICAgICAgICAgbGV0IGk7XG4gICAgICAgICAgICAgICAgICAgIGxldCBjaHI7XG4gICAgICAgICAgICAgICAgICAgIGZvciAoaSA9IDA7IGkgPCBzLmxlbmd0aDsgaSsrKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICBjaHIgPSBzLmNoYXJDb2RlQXQoaSk7XG4gICAgICAgICAgICAgICAgICAgICAgICBoYXNoID0gKChoYXNoIDw8IDUpIC0gaGFzaCkgKyBjaHI7XG4gICAgICAgICAgICAgICAgICAgICAgICBoYXNoIHw9IDA7IC8vIENvbnZlcnQgdG8gMzJiaXQgaW50ZWdlclxuICAgICAgICAgICAgICAgICAgICB9XG5cbiAgICAgICAgICAgICAgICAgICAgLy8gU2hvdyB0aGUgU2VudHJ5IHJlcG9ydCBkaWFsb2dcbiAgICAgICAgICAgICAgICAgICAgZ2xvYmFsU2hvd1NlbnRyeVJlcG9ydERpYWxvZyhoYXNoLCBoaW50LmV2ZW50SWQpO1xuICAgICAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgfVxuICAgICAgICAgICAgLy8gUmV0dXJuIHRoZSBldmVudCBmb3IgU2VudHJ5IHRvIHByb2Nlc3NcbiAgICAgICAgICAgIHJldHVybiBldmVudDtcbiAgICAgICAgfSxcbiAgICB9KTtcblxuICAgIFNlbnRyeS5jb25maWd1cmVTY29wZSgoc2NvcGUpID0+IHtcbiAgICAgICAgc2NvcGUuc2V0VXNlcih7aWQ6IGdsb2JhbFBCWExpY2Vuc2V9KTtcbiAgICAgICAgc2NvcGUuc2V0VGFnKCdsaWJyYXJ5JywgJ3dlYi1pbnRlcmZhY2UnKTtcbiAgICB9KTtcblxuICAgIGlmIChnbG9iYWxMYXN0U2VudHJ5RXZlbnRJZCkge1xuICAgICAgICBnbG9iYWxTaG93U2VudHJ5UmVwb3J0RGlhbG9nKGdsb2JhbExhc3RTZW50cnlFdmVudElkKTtcbiAgICB9XG59KTsiXX0=